AsOrdered(TSource) Method (ParallelQuery(TSource))

Task Parallel System.Threading

Enables treatment of a data source as if it was ordered, overriding the default of unordered. AsOrdered may only be invoked on sequences returned by AsParallel, ParallelEnumerable.Range, and ParallelEnumerable.Repeat.

Namespace:  System.Linq
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function AsOrdered(Of TSource) ( _
	source As ParallelQuery(Of TSource) _
) As ParallelQuery(Of TSource)
C#
public static ParallelQuery<TSource> AsOrdered<TSource>(
	ParallelQuery<TSource> source
)

Parameters

source
Type: System.Linq..::.ParallelQuery<(Of <(TSource>)>)
The input sequence.

Type Parameters

TSource
The type of elements of source.

Return Value

The source sequence which will maintain ordering in the query.

Remarks

A natural tension exists between performance and preserving order in parallel processing. By default, a parallelized query behaves as if the ordering of the results is arbitrary unless AsOrdered is applied or there is an explicit OrderBy operator in the query.

Exceptions

ExceptionCondition
System..::.InvalidOperationException Thrown if source is not one of AsParallel, ParallelEnumerable.Range, or ParallelEnumerable.Repeat.
System..::.ArgumentNullException source is a null reference (Nothing in Visual Basic).

See Also